import Vue from 'vue';
import VueRouter from 'vue-router';
import {Routers} from './routerArr';
// import api from '../api/index';

Vue.use(VueRouter);
// let params = {
//   type:'',
//   output:Routers
// }
// api.getPermissions(params).then(res=>{
//   console.log(res,666666);
// })

const router = new VueRouter({
	mode:'hash',
	routes:Routers
});

router.beforeEach((to,from,next) => {
	let token = localStorage.getItem('liankun_user');
	let count = localStorage.getItem('count');
	if(token){
		if(to.path=='/partnerLogin'){
			next(false)
		}else{
			if(count>1){
				if(to.path=='/selectStore'){
					next()
				}else{
					next(false)
				}
			}else{
				if(to.path=='/selectStore'){
					next(false)
				}else{
					next()
				}
			}
		}
	}else{
		if(to.path=='/partnerLogin'){
			next()
		}else{
			next('/partnerLogin')
		}
	}
});

export default router;